<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="评论内容" prop="videoName">
        <el-input
          v-model="queryParams.content"
          placeholder="评论内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

         <el-form-item label="发圈人名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="发圈人名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

         <el-form-item label="发圈人手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="发圈人手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker
          clearable
          size="small"
          style="width: 200px"
          v-model="queryParams.beginTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开始时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="expireTime">
        <el-date-picker
          clearable
          size="small"
          style="width: 200px"
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择过期时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['content:world:add']"-->
      <!--        >新增</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['content:world:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['content:world:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['content:world:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="worldList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="发布的信息" :show-overflow-tooltip="true" align="center" prop="content" />
      <el-table-column label="图片地址json" :show-overflow-tooltip="true" align="center" prop="url" />
      <el-table-column label="发布时间" align="center" prop="publishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="0是未发布1是发布"
        align="center"
        prop="isPublish"
        :formatter="isPublishFormat"
      />
      <el-table-column label="发布者id" align="center" prop="userId" />
      <el-table-column label="只允许谁看" align="center" prop="viewUserId" />
      <el-table-column label="不给谁看" align="center" prop="noViewUserId" />
      <el-table-column label="阅览人数" align="center" prop="readNum" />
      <el-table-column label="喜欢人数" align="center" prop="likeNum" />
      <el-table-column label="不喜欢人数" align="center" prop="noLikeNum" />
      <el-table-column label="点赞人数" align="center" prop="tapNum" />
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column label="是否检查通过" align="center" prop="isCheck" :formatter="isCheckFormat" />
      <el-table-column label="是否删除" align="center" prop="isDelete" :formatter="isDeleteFormat" />
      <el-table-column label="是否置顶" align="center" prop="isTop" :formatter="isTopFormat" />
      <el-table-column label="是否是广告" align="center" prop="isAdd" :formatter="isAddFormat" />
      <el-table-column label="操作" align="center" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['content:world:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['content:world:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改圈子管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="阅览人数" prop="readNum">
          <el-input v-model="form.readNum" placeholder="请输入阅览人数" />
        </el-form-item>
        <el-form-item label="喜欢人数" prop="likeNum">
          <el-input v-model="form.likeNum" placeholder="请输入喜欢人数" />
        </el-form-item>
        <el-form-item label="不喜欢人数" prop="noLikeNum">
          <el-input v-model="form.noLikeNum" placeholder="请输入不喜欢人数" />
        </el-form-item>
        <el-form-item label="点赞人数" prop="tapNum">
          <el-input v-model="form.tapNum" placeholder="请输入点赞人数" />
        </el-form-item>

        <el-form-item label="照片" 相册>
          <div class="demo-image">
            <div class="block" v-for="fit in form.urls" :key="fit">
              <span class="demonstration"></span>
              <el-image
                style="width: 100px; height: 100px;"
                :src="fit"
                :preview-src-list=" form.urls"
              ></el-image>
               <el-button type="primary" @click="solve(fit)" >违规处理</el-button>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否检查通过">
          <el-radio-group v-model="form.isCheck">
            <el-radio
              v-for="dict in isCheckOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="输入备注信息" prop="remark">
          <el-input v-model="form.remark" placeholder="输入备注信息" />
        </el-form-item>
          <el-form-item label="发圈内容" prop="content">
          <el-input  type="textarea" v-model="form.content" placeholder="发圈内容" readonly="readonly"/>
           <el-button type="primary" @click="solveTxt" >违规处理</el-button>
        </el-form-item>
        <el-form-item label="是否删除">
          <el-radio-group v-model="form.isDelete">
            <el-radio
              v-for="dict in isDeleteOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否置顶">
          <el-radio-group v-model="form.isTop">
            <el-radio
              v-for="dict in isTopOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="广告">
          <el-radio-group v-model="form.isAdd">
            <el-radio
              v-for="dict in isAddOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWorld,
  getWorld,
  delWorld,
  addWorld,
  updateWorld,
  exportWorld,
  solve,
  solveTxt
} from "@/api/content/world";

export default {
  name: "World",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 圈子管理表格数据
      worldList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 0是未发布1是发布字典
      isPublishOptions: [],
      // 是否检查通过字典
      isCheckOptions: [],
      // 是否删除字典
      isDeleteOptions: [],
      // 是否置顶字典
      isTopOptions: [],
      // 是否是广告字典
      isAddOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_publish_status").then(response => {
      this.isPublishOptions = response.data;
    });
    this.getDicts("plat_world_check_status").then(response => {
      this.isCheckOptions = response.data;
    });
    this.getDicts("video_delete").then(response => {
      this.isDeleteOptions = response.data;
    });
    this.getDicts("video_is_top").then(response => {
      this.isTopOptions = response.data;
    });
    this.getDicts("sys_ads_status").then(response => {
      this.isAddOptions = response.data;
    });
  },
  methods: {
    /** 查询圈子管理列表 */
    getList() {
      this.loading = true;
      listWorld(this.queryParams).then(response => {
        console.log(response.rows);
        this.worldList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 0是未发布1是发布字典翻译
    isPublishFormat(row, column) {
      return this.selectDictLabel(this.isPublishOptions, row.isPublish);
    },
    // 是否检查通过字典翻译
    isCheckFormat(row, column) {
      return this.selectDictLabel(this.isCheckOptions, row.isCheck);
    },
    // 是否删除字典翻译
    isDeleteFormat(row, column) {
      return this.selectDictLabel(this.isDeleteOptions, row.isDelete);
    },
    // 是否置顶字典翻译
    isTopFormat(row, column) {
      return this.selectDictLabel(this.isTopOptions, row.isTop);
    },
    // 是否是广告字典翻译
    isAddFormat(row, column) {
      return this.selectDictLabel(this.isAddOptions, row.isAdd);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        content: undefined,
        url: undefined,
        publishTime: undefined,
        isPublish: "0",
        userId: undefined,
        isSelf: "0",
        viewUserId: undefined,
        noViewUserId: undefined,
        readNum: undefined,
        likeNum: undefined,
        noLikeNum: undefined,
        tapNum: undefined,
        isCheck: "0",
        isDelete: "0",
        isTop: "0",
        isAdd: "0",
        remark: undefined,
        urls: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加圈子管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getWorld(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改圈子管理";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateWorld(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addWorld(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除圈子管理编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delWorld(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有圈子管理数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportWorld(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        })
        .catch(function() {});
    },
    
    solve(fit){
         console.log(fit)
           solve(fit,this.form).then(response => {
                // this.msgSuccess("修改成功");
                // this.open = false;
                // this.getList();
                 console.log(response)
                 this.form = response.data;
               
            });
    },
     solveTxt(){
      
           solveTxt(this.form).then(response => {
                // this.msgSuccess("修改成功");
                // this.open = false;
                // this.getList();
                 console.log(response)
                 this.form = response.data;
               
            });
    }
  }
};
</script>
